#!/usr/bin/python

import sys
import re
from Bio import Entrez
from Bio import SeqIO

Entrez.email = "jimmysaw@gmail.com"

filename = sys.argv[1]
f = open(filename, "rU")
fh = f.readlines()

m1 = re.compile('val=(\w+\.\d)')

acc_list = []

for line in fh:
    if m1.search(line):
        pattern = m1.search(line)
        acc_list.append(pattern.group(1))

acc = acc_list[0]

try:
    handle = Entrez.efetch(db="protein", id=acc, rettype="gp")
    rec = SeqIO.read(handle, "genbank")
    print rec.format('fasta').rstrip()
except:
    print "Not working!!"

f.close()